<template>
  <div class="row-image">
    <div class="cover">
      <img :src="cover" />
    </div>

    <div class="container">
      <div class="heading">
        <div class="desc van-multi-ellipsis--l2">{{ `【${name}】${desc}` }}</div>
        <div class="tags">
          <van-tag v-for="(item, index) in tags" :key="index" plain color="#4586FF">{{ item }}</van-tag>
        </div>
      </div>

      <div class="sale">
        <span>优惠金额：</span>
        <span :style="{ color: '#FF6669' }">{{ `-¥${sale}` }}</span>
      </div>
    </div>

    <div class="cashier">
      <div class="price">
        <span>¥</span>
        <span :style="{ fontSize: '16px' }">{{ intager }}</span>
        <span>{{ `.${decimal}` }}</span>
      </div>
      <div class="number">{{ `X ${number}` }}</div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Tag } from 'vant'

Vue.use(Tag)

export default {
  props: {
    cover: {
      type: String,
      default: ''
    },

    name: {
      type: String,
      default: ''
    },

    desc: {
      type: String,
      default: ''
    },

    tags: {
      type: Array,
      default: () => []
    },

    sale: {
      type: [Number, String],
      default: 0
    },

    price: {
      type: [Number, String],
      default: 0
    },

    number: {
      type: [Number, String],
      default: 1
    }
  },

  computed: {
    intager() {
      const { price } = this
      const [intager] = String(Number(price).toFixed(2)).split('.')
      return intager
    },

    decimal() {
      const { price } = this
      const [intager, decimal] = String(Number(price).toFixed(2)).split('.')
      return decimal
    }
  }
}
</script>

<style lang="less" scoped>
.row-image {
  padding: 14.5px 0;
  margin: 0 17px;
  border-top: 0.5px solid #eeeeee;
  border-bottom: 0.5px solid #eeeeee;
  display: flex;

  .cover {
    img {
      width: 90px;
      height: 90px;
    }
  }

  .container {
    flex: 1;
    display: flex;
    flex-flow: column;
    justify-content: space-between;
    height: 90px;
    padding: 0 13px 0 14px;

    .heading {
      .desc {
        font-size: 13px;
        color: #333333;
      }

      .tags {
        margin-top: 4.5px;

        > * {
          margin-right: 7px;
          background-color: rgba(69, 134, 255, 0.1);

          &:last-child {
            margin: 0;
          }
        }
      }
    }

    .sale {
      font-size: 13px;
      color: #999999;
    }
  }

  .cashier {
    text-align: right;
    font-size: 12px;

    .price {
      
      color: #333333;
    }

    .number {
      color: #BBBBBB;
      margin-top: 4px;
    }
  }
}
</style>